package jflowmap.views.flowmap;

import java.awt.geom.Ellipse2D;

import edu.umd.cs.piccolo.PCanvas;
import edu.umd.cs.piccolo.PNode;

public class CircleDrawingStrategy extends VisualNodeDrawingStrategy {
   	private static final long serialVersionUID = 1L;

	public CircleDrawingStrategy(double x, double y, VisualNode visualNode) {
        super(visualNode);
        final double size = 20.0f;
        this.append(new Ellipse2D.Double(-size/2,-size/2, size, size), true);
        this.translate(x, y);
        updateVisibility();
    }
    
    private void updateVisibility () {
        if (!getVisualNode().hasEdges()) {
            this.setVisible(false);
        } else {
            this.setVisible(true);
        }
    }

    @Override
    public void showLegend() {
    }

    @Override
    public void hideLegend() {
    }

    private PNode parent = null;
    
	@Override
	public PCanvas startExport() {
		PCanvas canvas = new PCanvas();
		canvas.setBounds(0, 0, (int) getWidth(), (int) getHeight());
		
		parent = this.getParent();
		canvas.getLayer().addChild(this);
		canvas.getCamera().setViewBounds(this.getFullBounds());
		
		return canvas;
	}

	@Override
	public void endExport() {
		if (parent != null) {
			parent.addChild(this);
		}
	}

	@Override
	public String getExportName() {
		return "node";
	}

	@Override
	public PCanvas exportLegend() {
		// TODO Auto-generated method stub
		return null;
	}
}
